package com.lhf.azkaban.springbatch.example.batchwriter;

import com.lhf.azkaban.springbatch.example.service.RepayOrderInfoService;
import com.lhf.azkaban.springbatch.example.utils.DateUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author:95780
 * @Date: 17:17 2019/11/21
 * @Description:
 */
@Component
public class RepayOrderMybatisWrite<RepayOrderInfo> implements ItemWriter<RepayOrderInfo> {
    @Autowired
    private RepayOrderInfoService repayOrderInfoService;

    private static final Logger logger = LogManager.getLogger(RepayOrderMybatisWrite.class);
    @Override
    public void write(List<? extends RepayOrderInfo> list) throws Exception {
        logger.info("======RepayOrderMybatisWrite Begin ======   time:   " + DateUtil.parseDateTime(LocalDateTime.now(), DateUtil.PATTERN_DEFAULT_DATA));

        //批量保存数据到数据库中
        repayOrderInfoService.saveRepayOrderInfoBatch((List<com.lhf.azkaban.springbatch.example.mode.RepayOrderInfo>) list);

        logger.info("======RepayOrderMybatisWrite End ======   time:   " + DateUtil.parseDateTime(LocalDateTime.now(), DateUtil.PATTERN_DEFAULT_DATA));
    }
}
